package com.pickgliss.light3d.display
{
	import com.pickgliss.toplevel.StageReferance;
	import flash.display.Stage;
	import flash.display.Stage3D;
	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	public class World3D
	{
		
		public function World3D(frameRata:int = 30,camera:Camera3D = null)
		{
			_frameRate = frameRata;
			_camera = camera;
			initWorld();
		}

		protected var _camera:Camera3D;
		protected var _frameRate:int;
		protected var _scene:Scene3D;
		protected var _stage3D:Stage3D;
		
		public function pause():void
		{
			StageReferance.stage.removeEventListener(Event.ENTER_FRAME,mainLoop);
		}
		
		public function get scene():Scene3D
		{
			return _scene;
		}
		
		public function set scene(s:Scene3D):void
		{
			if(_scene != null)_scene.dispose();
			_scene = s;
		}
		
		public function start():void
		{
			StageReferance.stage.addEventListener(Event.ENTER_FRAME,mainLoop);
		}
		
		protected function createDefaultCamera():Camera3D
		{
			return new Camera3D();
		}
		
		protected function initWorld():void
		{
			if(_camera == null)_camera = createDefaultCamera();
			StageReferance.stage.frameRate=_frameRate;
			StageReferance.stage.addEventListener(Event.RESIZE, onResize);
			StageReferance.stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			StageReferance.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			StageReferance.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			_stage3D=StageReferance.stage.stage3Ds[0];
			_stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
			_stage3D.addEventListener(ErrorEvent.ERROR, onStage3DError);
			_stage3D.requestContext3D();
		}
		
		protected function mainLoop(event:Event):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onContextCreated(event:Event):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onMouseDown(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onMouseMove(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onMouseUp(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onResize(event:Event):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onStage3DError(event:ErrorEvent):void
		{
			// TODO Auto-generated method stub
			
		}
	}
}